<template>
	<view class="safecontent">
		<view class="tn-flex tn-flex-direction-row tn-flex-row-around tn-padding-top">
			<view class="tn-flex-4 tn-text-center">
				教室名称
			</view>
			<view class="tn-flex-3 tn-text-center">
				巡查时间
			</view>
			<view class="tn-flex-5 tn-text-center">
				风险级别
			</view>
		</view>
		<view class="" v-if="dataList.length">
			
		<view class="tn-flex tn-flex-direction-row tn-flex-row-around tn-padding-top" v-for="(item,index) in dataList" :key="index">
			<view class="tn-flex-4 tn-text-center">
				{{item.classRoomName}}
			</view>
			<view class="tn-flex-3 tn-text-center time-v">
				{{item.createdTime}}
			</view>
			<view class="tn-flex-5 tn-text-center">
				<text class="">{{item.riskLevelStr}}</text>
				<text class="tn-icon-right tn-padding-left" @click="goDetail(item)"></text>
			</view>
		</view>	
		</view>
		
		<view class="tn-margin-top-xl tn-padding-top tn-flex tn-flex-row-center" v-else>
			<tn-empty mode="data"></tn-empty>
		</view>
		<tn-button class="fabu__btn" width="80rpx" height="80rpx" backgroundColor="tn-cool-bg-color-7" :fontSize="40" shape="icon" margin="10rpx 10rpx" @click="gofabu"><text class="tn-icon-camera"></text></tn-button>
    
	</view>
</template>

<script>
	
export default {
	name: 'safelist',
	data(){
			return {
				pageIndex: 1,
				totalPage:0,
				dataList: [],
				classId: null,
			}
	},
	onPullDownRefresh() {
		this.pageIndex = 1
		this.getlist();
		console.log('下拉刷新------')
	},
	onReachBottom() {
		this.pageIndex++;
		this.getlist();
		console.log('上啦更多-------')
	},
	onLoad:function(options){
	    console.log(options.id);   // 2
		this.classId = options.id
		this.getlist();
	},
	onShow() {
		// this.getlist();
	},
	mounted() {
		
	},
	methods: {
		gofabu(){
			
				let that = this;
				uni.scanCode({
					onlyFromCamera: true,
					success: function (res) {
						// console.log('条码类型：' + res.scanType);
						console.log('条码内容：' + JSON.stringify(res) );
						console.log('条码内容：' + res.result);
						// let urlobj = that.queryURLParams(res.result)
						let arr = res.result.split('=')
						let id = arr[1]
						console.log('id === ',id)
						if(id){
							uni.navigateTo({
								url:'/pagesA/yuanwuduan/safeInput?id='+id
							})
						}else if(res.result.indexOf('QR') > -1){
							uni.navigateTo({
								url:'/pagesA/yuanwuduan/safeInput?id='+res.id
							})
						}
					}
				});
			// uni.navigateTo({
			// 	url: '/pagesA/yuanwuduan/safeInput?id='+ '08db9a6d-f8cd-4d71-81b6-7fe73e707d39'
			// })
		},
		
		queryURLParams(url){
		    let pattern = /(\w+)=(\w+)/ig; //定义正则表达式
		    let parames = {}; // 定义参数对象
		    url.replace(pattern, ($, $1, $2) => {
		      parames[$1] = $2;
		    });
		    return parames;
		},
		goDetail(item){
			uni.navigateTo({
				url: '/pagesA/yuanwuduan/safedetail?id='+item.id
			})
		},
		getlist(){
			if(this.totalPage > 0 && this.pageIndex > this.totalPage){
				this.$refs.toast.show({
				  title: '',
				  content: '没有更多了',
				  icon: '',
				  image: '',
				  duration: 1000
				})
				return;
			}
			let params = {
				PageNo: this.pageIndex,
				PageSize: 10
			}
			if(this.classId){
				params = {
					pageNo: this.pageIndex,
					pageSize: 10,
					gardenHouseClassRoomId: this.classId
				}
			}else{
				params = {
					pageNo: this.pageIndex,
					pageSize: 10
				}
			}
			this.request({
				url: '/InspectionRecord/Page',
				method: 'get',
				params: params,
			}).then(res => {
				
					if(res.code == 200){
						if(this.pageIndex == 1){
							this.dataList = [];
						}
						let rows = res.data.rows;
						this.totalPage = res.data.totalPage;
						rows.forEach(item => {
							this.dataList.push(item);
						})
						uni.stopPullDownRefresh()
					}
			})
		},
		
	},
}
</script>

<style lang="scss">
	.safecontent{
		color: #555555;
	}
	.tnmr-10{
		margin-right: 10rpx;
	}
	.fabu__btn{
		  position: fixed;
		  bottom: 15%;
		  right: 10px;
	}
	.time-v{
		font-size: 24rpx;
	}
</style>